package com.boho.estates.usual.service;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import cn.boho.framework.context.ActionContext;
import cn.boho.framework.exception.UserOperationException;
import cn.boho.framework.po.ComboPager;
import cn.boho.framework.po.DynaBeanMap;
import cn.boho.framework.po.POUtils;
import cn.boho.framework.po.Pager;
import cn.boho.framework.service.MessageService;

import com.boho.base.dao.DaoHelper;
import com.boho.common.Constant;
import com.boho.common.SystemUtils;
import com.boho.estates.po.TCheckInfoDetailPO;
import com.boho.estates.po.TCheckInfoPO;
import com.boho.estates.po.TFaAllocateDetailPO;
import com.boho.estates.po.TFaAllocatePO;
import com.boho.estates.po.TFaChangeFlowPO;
import com.boho.estates.po.TFixedAssetsDetailPO;
import com.boho.estates.po.TSuppliersPO;
import com.boho.estates.suppliers.dao.TSuppliersDao;
import com.boho.estates.usual.dao.TCheckInfoDao;
import com.boho.estates.usual.dao.TFixedAssetsDetailDao;

public class UsualService {
	/**
	* 分页查询所有【资产详细信息:T_FIXED_ASSETS_DETAIL】信息
	* @param con
	* @param pager
	* @return
	* @throws Exception
	* @date 2011-10-31
	* @author 许福辉
	*
	*/
	public static ComboPager queryTFixedAssetsDetailByPager(Connection con,Pager pager,String  BARCODE
			,String FIXED_ASSETS_NAME,String FIXED_ASSETS_TYPE
			,double STOCK_PRICE1,double STOCK_PRICE2
			,String REMARK,String FA_STATUS,String FIXED_ASSETS_NATURE,String SEQ_FIELD,String SEQ_WAY, String departIds)throws Exception{
		ComboPager cp = TFixedAssetsDetailDao.queryTFixedAssetsDetailByPager(con,pager,BARCODE,FIXED_ASSETS_NAME,FIXED_ASSETS_TYPE
				,STOCK_PRICE1,STOCK_PRICE2,REMARK,FA_STATUS,FIXED_ASSETS_NATURE,SEQ_FIELD,SEQ_WAY,departIds);
		DaoHelper.setTpersonField(con, cp, "_NAME", "WITH_MANANGER");//替换人员
		DaoHelper.setTDepartmentField(con, cp, "_NAME", "DEPARTMENT_NO","GS_DEPARTMENT_NO");//替换部门
		DaoHelper.setTsuppliersField(con, cp, "_NAME", "SUPPLIERS_NO");//替换供应商
		DaoHelper.setDictField(con, cp, "FIXED_ASSETS_TYPE", "_NAME", "FIXED_ASSETS_TYPE");
		DaoHelper.setDictField(con, cp, "FIXED_ASSETS_NATURE", "_NAME", "FIXED_ASSETS_NATURE");
		DaoHelper.setDictField(con, cp, "CHANGE_TYPE", "_NAME", "FA_STATUS");
		return cp;
	}
	/**
	* 分页查询所有【转移资产详细信息:T_FIXED_ASSETS_DETAIL】信息
	* @param con
	* @param pager
	* @return
	* @throws Exception
	* @date 2011-10-31
	* @author 许福辉
	*
	*/
	public static ComboPager queryTFaAllocateDetailByPager(Connection con,Pager pager,String  BARCODE
			,String FIXED_ASSETS_NAME)throws Exception{
		ComboPager cp = TFixedAssetsDetailDao.queryTFaAllocateDetailByPager(con,pager,BARCODE,FIXED_ASSETS_NAME);
		DaoHelper.setTpersonField(con, cp, "_NAME", "APPLICANT","OUT_DEPARTMENT_MANAGER");//替换人员
		DaoHelper.setTDepartmentField(con, cp, "_NAME", "DEPARTMENT_NO","ALLOCATE_IN_DEPARTMENT","ALLOCATE_OUT_DEPARTMENT");//替换部门
		//DaoHelper.setTDepartmentField(con, cp, "_NAME", "");//替换部门
		return cp;
	}
	/**
	* 分页查询所有【转移资产详细信息:T_FIXED_ASSETS_DETAIL】信息
	* @param con
	* @param pager
	* @return
	* @throws Exception
	* @date 2011-10-31
	* @author 许福辉
	*
	*/
	public static ComboPager queryTFaAllocateDetailByIdPager(Connection con,Pager pager,String  id)throws Exception{
		ComboPager cp = TFixedAssetsDetailDao.queryTFaAllocateDetailByIdPager(con,pager,id);
		DaoHelper.setTDepartmentField(con, cp, "_NAME", "DEPARTMENT_NO");//替换部门
		return cp;
	}
	/**
	* 分页查询所有【转移变更详细信息:T_FIXED_CHANGE_FLOW】信息
	* @param con
	* @param pager
	* @return
	* @throws Exception
	* @date 2011-10-31
	* @author 许福辉
	*
	*/
	public static ComboPager queryTFixedChangeFlowByIdPager(Connection con,Pager pager,String barcode,String changeType)throws Exception{
		ComboPager cp = TFixedAssetsDetailDao.queryTFixedChangeFlowByIdPager(con,pager,barcode,changeType);
		DaoHelper.setDictField(con, cp, "CHANGE_TYPE", "_NAME", "CHANGE_TYPE");
		DaoHelper.setTpersonField(con, cp, "_NAME", "PERSON");
		return cp;
	}
	/**
	* 按类型分页查询所有【资产详细信息:T_FIXED_ASSETS_DETAIL】信息
	* @param con
	* @param pager
	* @return
	* @throws Exception
	* @date 2011-10-31
	* @author 许福辉
	*
	*/
	public static ComboPager queryTFixedAssetsDetailByTypePager(Connection con,Pager pager,String  BARCODE,String type)throws Exception{
		ComboPager cp = TFixedAssetsDetailDao.queryTFixedAssetsDetailByTypePager(con,pager,BARCODE,type);
		DaoHelper.setTsuppliersField(con, cp, "_NAME", "SUPPLIERS_NO");//替换供应商
		return cp;
	}
	/**
	* 分页查询所有ID串【资产详细信息:T_FIXED_ASSETS_DETAIL】信息
	* @param con
	* @param pager
	* @return
	* @throws Exception
	* @date 2011-10-31
	* @author 许福辉
	*
	*/
	public static ComboPager queryTFixedAssetsDetailByIdStrByPager(Connection con,Pager pager,String id)throws Exception{
		ComboPager cp = TFixedAssetsDetailDao.queryTFixedAssetsDetailByIdStrByPager(con,pager,id);
		DaoHelper.setTpersonField(con, cp, "_NAME", "WITH_MANANGER");//替换人员
		DaoHelper.setTDepartmentField(con, cp, "_NAME", "DEPARTMENT_NO");//替换部门
		DaoHelper.setTsuppliersField(con, cp, "_NAME", "SUPPLIERS_NO");//替换供应商
		return cp;
	}
	
	/**
	* 根据主键【条形码:BARCODE|】获得信息
	* @param con
	* @param barcode 条形码
	* @return
	* @throws Exception
	* @date 2011-10-31
	* @author 许福辉
	*
	*/
	public static DynaBeanMap getTFixedAssetsDetailByPk(Connection con,java.lang.Integer id,String BARCODE)throws Exception{
		DynaBeanMap dmp = TFixedAssetsDetailDao.getTFixedAssetsDetailByPk(con,id,BARCODE);
		DaoHelper.setTpersonField(con, dmp, "_NAME", "WITH_MANANGER");//替换人员
		DaoHelper.setTDepartmentField(con, dmp, "_NAME", "DEPARTMENT_NO");//替换部门
		DaoHelper.setTDepartmentField(con, dmp, "_NAME", "GS_DEPARTMENT_NO");//替换部门
		DaoHelper.setTsuppliersField(con, dmp, "_NAME", "SUPPLIERS_NO");//替换供应商
		DaoHelper.setDictField(con, dmp, "FIXED_ASSETS_TYPE", "_NAME", "FIXED_ASSETS_TYPE");
		DaoHelper.setDictField(con, dmp, "FIXED_ASSETS_NATURE", "_NAME", "FIXED_ASSETS_NATURE");
		DaoHelper.setDictField(con, dmp, "CHANGE_TYPE", "_NAME", "FA_STATUS");
		return dmp;
	}
	/**
	 * 添加资产详细信息
	 * @param con
	 * @param atx
	 * @throws Exception
	 */
	public static String addTFixedAssetsDetail(Connection con,ActionContext atx,String pic)throws Exception{
		TFixedAssetsDetailPO tFixedAssetsDetailPO = new TFixedAssetsDetailPO();
		String createBy = SystemUtils.getSessionUser(atx);
		int number = 0;
		StringBuffer detailStr = new StringBuffer();
		String FIXED_ASSETS_NATURE = atx.getStringValue("FIXED_ASSETS_NATURE");//资产性质
		
		//用户所属部门
		DynaBeanMap useesion =(DynaBeanMap)atx.getSessionValue(Constant.SESSION_PERSON_BEAN);
		if(useesion==null||useesion.get("DEPARTMENT_NO")==null) {
			UserOperationException uoe = new UserOperationException();
			atx.setErrorContext("ESTATES_USUAL_1004", MessageService.getMessage("ESTATES_USUAL_1004"),uoe);
			throw uoe;
		}
		
		//查询供应商
		String suppliersName = atx.getStringValue("SUPPLIERS_NO","");
		int suppliersId = addSuppliers(atx,suppliersName,createBy);
		
		String fName = atx.getStringValue("FIXED_ASSETS_NAME","");
		tFixedAssetsDetailPO.setFixedAssetsName(fName);
		tFixedAssetsDetailPO.setFixedAssetsType(atx.getStringValue("FIXED_ASSETS_TYPE"));
		tFixedAssetsDetailPO.setBrand(atx.getStringValue("BRAND"));
		tFixedAssetsDetailPO.setFixedAssetsNature(FIXED_ASSETS_NATURE);
		tFixedAssetsDetailPO.setDepartmentNo(useesion.get("DEPARTMENT_NO")==null?0:Integer.parseInt(useesion.get("DEPARTMENT_NO").toString()));//设置部门最后通后登录用户取部门
		java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd");    
		tFixedAssetsDetailPO.setStockDate(new java.util.Date(format.parse(atx.getStringValue("STOCK_DATE")).getTime()));
		tFixedAssetsDetailPO.setBeforPrice(atx.getDoubleValue("BEFOR_PRICE",0.0d));
		tFixedAssetsDetailPO.setStockPrice(atx.getDoubleValue("STOCK_PRICE",0.0d));
		tFixedAssetsDetailPO.setUseYear(atx.getStringValue("USE_YEAR"));
		tFixedAssetsDetailPO.setWarranty(atx.getStringValue("WARRANTY"));
		tFixedAssetsDetailPO.setSpecification(atx.getStringValue("SPECIFICATION"));
		tFixedAssetsDetailPO.setSuppliersNo(suppliersId);
		tFixedAssetsDetailPO.setFactoryNo(atx.getStringValue("FACTORY_NO"));
		tFixedAssetsDetailPO.setFaStatus("3");
		tFixedAssetsDetailPO.setStoredIn(atx.getStringValue("STORED_IN"));
		tFixedAssetsDetailPO.setWithMananger(atx.getStringValue("WITH_MANANGER"));
		tFixedAssetsDetailPO.setUseMananger(atx.getStringValue("USE_MANANGER",""));
		tFixedAssetsDetailPO.setRemark(atx.getStringValue("REMARK"));
		tFixedAssetsDetailPO.setCreateDate(new java.util.Date());
		tFixedAssetsDetailPO.setNcno(atx.getStringValue("NCNO"));
		tFixedAssetsDetailPO.setPic(pic);
		tFixedAssetsDetailPO.setCreateBy(createBy);
		tFixedAssetsDetailPO.setIsValid(1);
		tFixedAssetsDetailPO.setGsDepartmentNo(atx.getIntegerValue("GS_DEPARTMENT_NO",0));//资产归属部门
		tFixedAssetsDetailPO.setBarcode(FIXED_ASSETS_NATURE);
		number = atx.getIntegerValue("NUMBER",0);
		StringBuffer id = new StringBuffer();
		
		for(int i = 0 ;i<number;i++){
			id = new StringBuffer();
			POUtils.insert(con, tFixedAssetsDetailPO,false,id);
			StringBuffer treBar = new StringBuffer();
			treBar.append(FIXED_ASSETS_NATURE);
			treBar.append("_");
			for(int k=0;k<8-id.toString().length();k++){
				treBar.append("0");
			}
			treBar.append(id.toString());
			TFixedAssetsDetailPO t = new TFixedAssetsDetailPO();
			t.setId(Integer.parseInt(id.toString()));
			TFixedAssetsDetailPO v = new TFixedAssetsDetailPO();
			v.setBarcode(treBar.toString());
			POUtils.update(con, t, v,false);
			detailStr.append(id.toString()+",");
		}
		detailStr.append("0");
		return detailStr.toString();
	}
	/**
	 * 修改资产详细信息
	 * @param con
	 * @param atx
	 * @throws Exception
	 */
	public static void updateTFixedAssetsDetail(Connection con,ActionContext atx,String pic)throws Exception{
		
		int id = atx.getIntegerValue("ID",-1);
		String updateBy = SystemUtils.getSessionUser(atx);
		//查询供应商
		String suppliersName = atx.getStringValue("SUPPLIERS_NO","");
		int suppliersId = addSuppliers(atx,suppliersName,updateBy);
		
		TFixedAssetsDetailPO tFixedAssetsDetailPO = new TFixedAssetsDetailPO();
		TFixedAssetsDetailPO vFixedAssetsDetailPO = new TFixedAssetsDetailPO();
		TFaChangeFlowPO tFaChangeFlowPO = new TFaChangeFlowPO();
		tFixedAssetsDetailPO.setId(id);
		String fa_status = atx.getStringValue("FA_STATUS","");
		DynaBeanMap tempTf = TFixedAssetsDetailDao.getTFixedAssetsDetailByPk(con, id, "");
		if(tempTf!=null&&!fa_status.equals(tempTf.get("FA_STATUS").toString())){
			vFixedAssetsDetailPO.setFaStatus(fa_status);
			
			tFaChangeFlowPO.setBarcode(tempTf.get("BARCODE").toString());
			tFaChangeFlowPO.setChangeType(fa_status);
			tFaChangeFlowPO.setChangeDate(new java.util.Date());
			tFaChangeFlowPO.setChageReason("修改资产时候变更");
			tFaChangeFlowPO.setPerson(updateBy);
			tFaChangeFlowPO.setRemark("修改资产时候变更");
			tFaChangeFlowPO.setIsValid(1);
			tFaChangeFlowPO.setCreateBy(updateBy);
			tFaChangeFlowPO.setCreateDate(new java.util.Date());
			POUtils.insert(con, tFaChangeFlowPO,false);
		}
		
		String FIXED_ASSETS_NATURE = atx.getStringValue("FIXED_ASSETS_NATURE");
		vFixedAssetsDetailPO.setFixedAssetsName(atx.getStringValue("FIXED_ASSETS_NAME"));
		vFixedAssetsDetailPO.setBrand(atx.getStringValue("BRAND"));
		vFixedAssetsDetailPO.setFixedAssetsNature(FIXED_ASSETS_NATURE);
		vFixedAssetsDetailPO.setBeforPrice(atx.getDoubleValue("BEFOR_PRICE",0.0d));
		vFixedAssetsDetailPO.setStockPrice(atx.getDoubleValue("STOCK_PRICE",0.0d));
		vFixedAssetsDetailPO.setUseYear(atx.getStringValue("USE_YEAR"));
		vFixedAssetsDetailPO.setWarranty(atx.getStringValue("WARRANTY"));
		vFixedAssetsDetailPO.setSpecification(atx.getStringValue("SPECIFICATION"));
		vFixedAssetsDetailPO.setSuppliersNo(suppliersId);
		vFixedAssetsDetailPO.setFactoryNo(atx.getStringValue("FACTORY_NO"));
		vFixedAssetsDetailPO.setStoredIn(atx.getStringValue("STORED_IN"));
		vFixedAssetsDetailPO.setWithMananger(atx.getStringValue("WITH_MANANGER"));
		vFixedAssetsDetailPO.setUseMananger(atx.getStringValue("USE_MANANGER",""));
		vFixedAssetsDetailPO.setStockQuantity(atx.getIntegerValue("STOCK_QUANTITY"));
		vFixedAssetsDetailPO.setRemark(atx.getStringValue("REMARK"));
		vFixedAssetsDetailPO.setUpdateDate(new java.util.Date());
		vFixedAssetsDetailPO.setNcno(atx.getStringValue("NCNO"));
		vFixedAssetsDetailPO.setGsDepartmentNo(atx.getIntegerValue("GS_DEPARTMENT_NO"));//资产归属部门
		if(!"".equals(pic)){
		vFixedAssetsDetailPO.setPic(pic);}
		vFixedAssetsDetailPO.setUpdateBy(updateBy);
		vFixedAssetsDetailPO.setIsValid(1);
		vFixedAssetsDetailPO.setUpdateDate(new java.util.Date());
		POUtils.update(con, tFixedAssetsDetailPO, vFixedAssetsDetailPO,false);
	}
	/**
	 * 修改资产详细信息
	 * @param con
	 * @param atx
	 * @throws Exception
	 */
	public static void deleteTFixedAssetsDetail(Connection con,ActionContext atx)throws Exception{
		
		int id = atx.getIntegerValue("ID",-1);
		String updateBy = SystemUtils.getSessionUser(atx);
		
		TFixedAssetsDetailPO tFixedAssetsDetailPO = new TFixedAssetsDetailPO();
		TFixedAssetsDetailPO vFixedAssetsDetailPO = new TFixedAssetsDetailPO();
		
		tFixedAssetsDetailPO.setId(id);
		
		vFixedAssetsDetailPO.setUpdateBy(updateBy);
		vFixedAssetsDetailPO.setIsValid(0);
		vFixedAssetsDetailPO.setUpdateDate(new java.util.Date());
		POUtils.update(con, tFixedAssetsDetailPO, vFixedAssetsDetailPO,false);
	}
	
	/**
	 * 添加调拨信息
	 * @param con
	 * @param tFaAllocatePO
	 * @param BARCODE
	 * @throws Exception
	 */
	public static void addTFaAllocate(Connection con,ActionContext atx)throws Exception{
		TFaAllocatePO tFaAllocatePO = new TFaAllocatePO();
		
		String createBy = SystemUtils.getSessionUser(atx);
		//用户所属部门
		DynaBeanMap useesion =(DynaBeanMap)atx.getSessionValue(Constant.SESSION_PERSON_BEAN);
		if(useesion==null||useesion.get("DEPARTMENT_NO")==null)
		{
			UserOperationException uoe = new UserOperationException();
			atx.setErrorContext("ESTATES_USUAL_1004", MessageService.getMessage("ESTATES_USUAL_1004"),uoe);
			throw uoe;
		}
		java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd");    
		tFaAllocatePO.setFaAllocateDate(new java.util.Date(format.parse(atx.getStringValue("FA_ALLOCATE_DATE")).getTime()));
		tFaAllocatePO.setApplicant(atx.getStringValue("APPLICANT"));
		tFaAllocatePO.setAllocateInDepartment(atx.getStringValue("ALLOCATE_IN_DEPARTMENT"));
		tFaAllocatePO.setDepartmentNo(useesion.get("DEPARTMENT_NO")==null?0:Integer.parseInt(useesion.get("DEPARTMENT_NO").toString()));
		tFaAllocatePO.setNewStoredIn(atx.getStringValue("NEW_STORED_IN"));
		tFaAllocatePO.setInDepartmentManager(atx.getStringValue("IN_DEPARTMENT_MANAGER"));
		tFaAllocatePO.setNewWithMananger(atx.getStringValue("NEW_WITH_MANANGER"));
		tFaAllocatePO.setRemark(atx.getStringValue("REMARK"));
		tFaAllocatePO.setAllocateOutDepartment(atx.getStringValue("T_FA_ALLOCATE"));
		tFaAllocatePO.setOutDepartmentManager(atx.getStringValue("OUT_DEPARTMENT_MANAGER"));
		tFaAllocatePO.setOldStoredIn(atx.getStringValue("OLD_STORED_IN"));
		tFaAllocatePO.setOldWithMananger(atx.getStringValue("OLD_WITH_MANANGER"));
		tFaAllocatePO.setCreateDate(new java.util.Date());
		tFaAllocatePO.setCreateBy(createBy);
		tFaAllocatePO.setIsValid(1);
		StringBuffer id = new StringBuffer();
		POUtils.insert(con, tFaAllocatePO,false,id);
		
		
		Object[] barcode = atx.getArrayValue("TF_BARCODE");
		Object[] ancliary_item = atx.getArrayValue("ANCILARY_ITEM");
		Object[] allocate_reason = atx.getArrayValue("ALLOCATE_REASON");
		
		for(int i = 0 ;i<barcode.length;i++){
			DynaBeanMap tFd = TFixedAssetsDetailDao.getTFixedAssetsDetailByPk(con, Integer.parseInt(barcode[i].toString()),"");
			if(tFd!=null){
				TFaAllocateDetailPO tFaAllocateDetailPO = new TFaAllocateDetailPO();
				tFaAllocateDetailPO.setAllocateReason(allocate_reason[i].toString());
				tFaAllocateDetailPO.setAncilaryItem(ancliary_item[i].toString());
				tFaAllocateDetailPO.setBarcode(tFd.get("BARCODE").toString());
				tFaAllocateDetailPO.setBrand(tFd.get("BRAND").toString());
				tFaAllocateDetailPO.setCreateBy(createBy);
				tFaAllocateDetailPO.setSuppliersNo(tFd.get("SUPPLIERS_NO")==null?0:Integer.parseInt(tFd.get("SUPPLIERS_NO").toString()));
				tFaAllocateDetailPO.setCreateDate(new java.util.Date());
				tFaAllocateDetailPO.setDepartmentNo(useesion.get("DEPARTMENT_NO")==null?0:Integer.parseInt(useesion.get("DEPARTMENT_NO").toString()));
				tFaAllocateDetailPO.setFaAllocateNo(Integer.parseInt(id.toString()));
				tFaAllocateDetailPO.setFactoryNo(tFd.get("FACTORY_NO").toString());
				tFaAllocateDetailPO.setFixedAssetsName(tFd.get("FIXED_ASSETS_NAME").toString());
				tFaAllocateDetailPO.setQuantity(1);
				tFaAllocateDetailPO.setIsValid(1);
				POUtils.insert(con, tFaAllocateDetailPO,false);
				
				TFixedAssetsDetailPO t = new TFixedAssetsDetailPO();
				t.setId(Integer.parseInt(barcode[i].toString()));
				TFixedAssetsDetailPO v = new TFixedAssetsDetailPO();
				v.setGsDepartmentNo(atx.getIntegerValue("ALLOCATE_IN_DEPARTMENT"));
				POUtils.update(con, t, v,false);
			}
		}
			//UserOperationException uoe = new UserOperationException();
			//atx.setErrorContext("ESTATES_USUAL_1002", MessageService.getMessage("ESTATES_USUAL_1002"),uoe);
	}
	
	
	/**
	 * 新增盘点单
	 * @param con
	 * @param atx
	 * @throws Exception
	 */
	public static void addTCheckInfo(Connection con,ActionContext atx)throws Exception{
		TCheckInfoPO tCheckInfoPO = new TCheckInfoPO();
		String createBy = SystemUtils.getSessionUser(atx);
		String check_no = atx.getStringValue("CHECK_NO");
		//判断盘点单号是否存在
		DynaBeanMap temTcheck =(DynaBeanMap)TCheckInfoDao.getTCheckInfoByCheckNO(con, check_no);
		if(temTcheck!=null&&temTcheck.get("ID")!=null)
		{
			UserOperationException uoe = new UserOperationException();
			atx.setErrorContext("ESTATES_USUAL_1006", MessageService.getMessage("ESTATES_USUAL_1006"),uoe);
			throw uoe;
		}
		
		DynaBeanMap sessiondbm = (DynaBeanMap)atx.getSessionValue(Constant.SESSION_PERSON_BEAN);
		Integer departId = (Integer)sessiondbm.get("DEPARTMENT_NO");
		
		java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd");
		tCheckInfoPO.setCheckNo(check_no);
		tCheckInfoPO.setChangeBeginDate(format.parse(atx.getStringValue("CHANGE_BEGIN_DATE")));
		tCheckInfoPO.setChageStatus("1");
		tCheckInfoPO.setChengBefullof(0.0d);
		tCheckInfoPO.setChengLose(0.0d);
		tCheckInfoPO.setBefullofLose(0.0d);
		tCheckInfoPO.setPerson(atx.getStringValue("PERSON",""));
		tCheckInfoPO.setIsValid(1);
		tCheckInfoPO.setDepartmentNo(departId);
		tCheckInfoPO.setCreateBy(createBy);
		tCheckInfoPO.setCreateDate(new java.util.Date());
		
		StringBuffer tcheckid = new StringBuffer();
		POUtils.insert(con, tCheckInfoPO, false,tcheckid);
		
		//取得当前所有的资产
		List TFixedAssetsDetailList = TFixedAssetsDetailDao.queryTFixedAssetsDetailByNotStatus(con, "6");
		List tCheckInfoDetailList = new ArrayList();
		for (int i = 0; i < TFixedAssetsDetailList.size(); i++) {
			DynaBeanMap dbm = (DynaBeanMap) TFixedAssetsDetailList.get(i);
			TCheckInfoDetailPO t = new TCheckInfoDetailPO();
			t.setCheckNo(check_no);
			t.setStockPrice(dbm.get("STOCK_PRICE")==null?0d:Double.parseDouble(dbm.get("STOCK_PRICE").toString()));
			t.setBarcode(dbm.get("BARCODE").toString());
			t.setFixedAssetsNo(Integer.parseInt(dbm.get("ID").toString()));
			t.setFixedAssetsName(dbm.get("FIXED_ASSETS_NAME").toString());
			t.setDepartmentName(dbm.get("DEPARTMENT_NO")==null?"":dbm.get("DEPARTMENT_NO").toString());
			t.setStoredIn(dbm.get("STORED_IN")==null?"":dbm.get("STORED_IN").toString());
			t.setWithMananger(dbm.get("WITH_MANANGER")==null?"":dbm.get("WITH_MANANGER").toString());
			t.setCreateBy(createBy);
			t.setCreateDate(new java.util.Date());
			t.setIsCheck(0);
			t.setIsValid(1);
			t.setNcno(dbm.get("NCNO")==null?"":dbm.get("NCNO").toString());
			tCheckInfoDetailList.add(t);
		}
		if(tCheckInfoDetailList.size()>0)
		{
			POUtils.insertPoList(con, tCheckInfoDetailList, false);
		}
		DynaBeanMap dbm = new DynaBeanMap();
		dbm.put("ID", check_no);
		atx.setObjValue("T_CHECK_INFO", dbm);
	}
	
	
	/**
	 * 判断供应商，如果存在返回ID，不存在，新增供应商并返回ID
	 * @param con
	 * @param suppliersName
	 * @param createBy
	 * @return
	 * @throws Exception
	 */
	public static int addSuppliers(ActionContext atx,String suppliersName,String createBy)throws Exception{
		
		int supplier = 0;
		if(!"".equals(suppliersName)){
			String departIds  = (String)atx.getSessionValue(com.boho.common.Constant.SESSION_DEPART_ARRAY);
			DynaBeanMap suppleiers =(DynaBeanMap)TSuppliersDao.getTSuppliersByName(atx.getConection(), suppliersName, departIds);
			if(suppleiers==null||suppleiers.get("SUPPLIERS_NO")==null) {
				TSuppliersPO ts = new TSuppliersPO();
				ts.setSuppliersName(suppliersName);
				ts.setSuppliersType("1");
				ts.setCreateBy(createBy);
				ts.setCreateDate(new java.util.Date());
				StringBuffer id = new StringBuffer();
				POUtils.insert(atx.getConection(), ts, false,id);
				supplier = Integer.parseInt(id.toString());
			}else{
				supplier = Integer.parseInt(suppleiers.get("SUPPLIERS_NO").toString());
			}
		}
		return supplier;
	}
}
